""" DateNotifier icon selection dialog """

from PyQt4.QtGui import *
from PyQt4.QtCore import QDir
from .UI.IconSelectionDialog import Ui_IconSelectionDialog

ICONS_PATH = ':UI/icons/'

class IconSelectionDialog(QDialog):
    def __init__(self, previousPath, parent):
        QDialog.__init__(self, parent)
        self.ui = Ui_IconSelectionDialog()
        self.ui.setupUi(self)

        self.selectedIcon = ""

        icons = QDir(ICONS_PATH).entryList()
        selectedItem = None
        for name in icons:
            icon = QIcon()
            path = ICONS_PATH + name
            icon.addPixmap(QPixmap(path))

            item = QListWidgetItem()
            item.setIcon(icon)
            item.path = path

            if path == previousPath:
                selectedItem = item

            self.ui.icons.addItem(item)

        if selectedItem is not None:
            selectedItem.setSelected(True)

    def selectIcon(self):
        item = self.ui.icons.currentItem()
        if item is None or not hasattr(item, 'path'):
            return

        self.selectedIcon = item.path
        self.accept()

    def selectNothing(self):
        self.selectedIcon = ""
        self.accept()

if __name__ == '__main__':
    import sys
    qApp = QApplication(sys.argv)
    IconSelectionDialog("", None).exec_()